<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script>
<link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">  
	<script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
	<script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
</head>
<body ng-app="">
 
<div class="col-md-6">
  <form role="form" name="myForm" ng-submit="submitForm(myForm.$valid)" class="form-horizontal" novalidate>
  <div class="form-group has-feedback">
   <div class="col-md-4">
   <label for="name">1.必填项</label>
   </div>
   <div class="col-md-8">
   <input class="form-control" id="name" name="name" type="text" required ng-model='user.name' />
   <span class="glyphicon glyphicon-ok form-control-feedback"
    ng-show="myForm.name.$dirty && myForm.name.$valid"></span>
   </div>
  </div>
  <div class="form-group has-feedback">
   <div class="col-md-4">
   <label for="minlength">2.最小长度=5</label>
   </div>
   <div class="col-md-8">
   <input type="text" id="minlength" name="minlength" ng-minlength="5" ng-model="user.minlength" class="form-control" />
   <span class="glyphicon glyphicon-ok form-control-feedback"
    ng-show="myForm.minlength.$dirty && myForm.minlength.$valid"></span>
   </div>
  </div>
  <div class="form-group has-feedback">
   <div class="col-md-4">
   <label for="maxlength">3.最大长度=20</label>
   </div>
   <div class="col-md-8">
   <input type="text" id="maxlength" name="maxlength" ng-model="user.maxlength" ng-maxlength="20" class="form-control" />
   <span class="glyphicon glyphicon-ok form-control-feedback"
    ng-show="myForm.maxlength.$dirty && myForm.maxlength.$valid"></span>
   </div>
  </div>
  <div class="form-group has-feedback">
   <div class="col-md-4">
   <label for="pattern">4. 模式匹配</label>
   </div>
   <div class="col-md-8">
   <input type="text" id="pattern" name="pattern" ng-model="user.pattern" ng-pattern="/^[a-zA-Z]*\d$/" class="form-control" />
   <span class="glyphicon glyphicon-ok form-control-feedback"
    ng-show="myForm.pattern.$dirty && myForm.pattern.$valid"></span>
   </div>
  </div>
  <div class="form-group has-feedback">
   <div class="col-md-4">
   <label for="email">5. 电子邮件</label>
   </div>
   <div class="col-md-8">
   <input type="email" id="email" name="email" ng-model="user.email" class="form-control" />
   <span class="glyphicon glyphicon-ok form-control-feedback"
    ng-show="myForm.email.$dirty && myForm.email.$valid"></span>
   </div>
  </div>
  <div class="form-group has-feedback">
   <div class="col-md-4">
   <label for="age">6. 数字</label>
   </div>
   <div class="col-md-8">
   <input type="number" id="age" name="age" ng-model="user.age" class="form-control" />
 
   <span class="glyphicon glyphicon-ok form-control-feedback"
    ng-show="myForm.age.$dirty && myForm.age.$valid"></span>
   </div>
  </div>
  <div class="form-group has-feedback">
   <div class="col-md-4">
   <label for="url"> 7. URL</label>
   </div>
   <div class="col-md-8">
   <input type="url" id="url" name="url" ng-model="user.url" class="form-control" />
   <span class="glyphicon glyphicon-ok form-control-feedback"
    ng-show="myForm.url.$dirty && myForm.url.$valid"></span>
   </div>
  </div>
  <div class="form-group text-center">
   <input class="btn btn-primary btn-lg" ng-disabled="myForm.$invalid" type="submit" value="提交" />
  </div>
  </form> 
 </div>
 <div class="col-md-12">
  1.必填项:{{user.name}}  
  $pristine 【没修改】：{{myForm.name.$pristine }}  
  $dirty【修改过】：{{myForm.name.$dirty}}  
  $invalid【验证失败】：{{myForm.name.$invalid}}  
  $invalid【验证成功】：{{myForm.name.$valid}}  
  required：{{myForm.name.$error.required}}  
  <br>
  2.最小长度=5:{{user.minlength}}
  $pristine 【没修改】：{{myForm.minlength.$pristine }}  
  $dirty【修改过】：{{myForm.minlength.$dirty}}  
  $invalid【验证失败】：{{myForm.minlength.$invalid}}  
  $invalid【验证成功】：{{myForm.minlength.$valid}}  
  $error【错误详情】：{{myForm.minlength.$error}}  <br>
  3.最大长度=20:{{user.maxlength}}
  $pristine 【没修改】：{{myForm.maxlength.$pristine }}  
  $dirty【修改过】：{{myForm.maxlength.$dirty}}  
  $invalid【验证失败】：{{myForm.maxlength.$invalid}}  
  $invalid【验证成功】：{{myForm.maxlength.$valid}}  
  $error【错误详情】：{{myForm.maxlength.$error}}  <br>
  4.模式匹配:{{user.pattern}}
  $pristine 【没修改】：{{myForm.pattern.$pristine }}  
  $dirty【修改过】：{{myForm.pattern.$dirty}}  
  $invalid【验证失败】：{{myForm.pattern.$invalid}}  
  $invalid【验证成功】：{{myForm.pattern.$valid}}  
  $error【错误详情】：{{myForm.pattern.$error}}  <br>
  5.电子邮件:{{user.email}}
  $pristine 【没修改】：{{myForm.email.$pristine }}  
  $dirty【修改过】：{{myForm.email.$dirty}}  
  $invalid【验证失败】：{{myForm.email.$invalid}}  
  $invalid【验证成功】：{{myForm.email.$valid}}  
  $error【错误详情】：{{myForm.email.$error}}  <br>
  6.数字:{{user.age}}
  $pristine 【没修改】：{{myForm.age.$pristine }}  
  $dirty【修改过】：{{myForm.age.$dirty}}  
  $invalid【验证失败】：{{myForm.age.$invalid}}  
  $invalid【验证成功】：{{myForm.age.$valid}}  
  $error【错误详情】：{{myForm.age.$error}}  <br>
  7.URL:{{user.url}}
  $pristine 【没修改】：{{myForm.url.$pristine }}  
  $dirty【修改过】：{{myForm.url.$dirty}}  
  $invalid【验证失败】：{{myForm.url.$invalid}}  
  $invalid【验证成功】：{{myForm.url.$valid}}  
  $error【错误详情】：{{myForm.url.$error}}  <br>
 </div>
 </body>
</html>
<script type="text/javascript">
 angular.module('myTest', [])
 .controller('myController', function($scope) {
  $scope.submitForm = function(isValid) {
  if (!isValid) {
   alert('验证失败');
  }
  };
 }
 );
</script>
 
 

</body>
</html>